const fs = require('fs');
const { Transform } = require('stream');

// 创建转换流（将字符转为大写）
const upperCaseTransform = new Transform({
  transform(chunk, encoding, callback) {
    this.push(chunk.toString().toUpperCase());
    callback();
  }
});

// 创建读写流
const readStream = fs.createReadStream('js流1/from.txt');
const writeStream = fs.createWriteStream('js流1/to.txt');

// 通过管道处理数据
readStream
  .pipe(upperCaseTransform)
  .pipe(writeStream)
  .on('finish', () => console.log('转换完成'));